package com.zhxh.nzpos.api;

import org.ksoap2.serialization.SoapObject;

import com.zhxh.nzpos.api.exception.AuthenticationException;
import com.zhxh.nzpos.api.exception.AuthorizationException;
import com.zhxh.nzpos.api.exception.CommunicationException;
import com.zhxh.nzpos.model.Buyin;
import com.zhxh.nzpos.model.Goods;


public class ConnectorBuyin {

	private KSoapExecutor soap;
	
	public ConnectorBuyin(){
		
		soap = new KSoapExecutor();
	}
	
	public boolean submitOrder(Buyin buyin, String posId, String CardID)
	        throws CommunicationException, AuthorizationException,
	        AuthenticationException {

		SoapObject getProjects = SoapObjectBuilder.start()
		        .withMethod("SubmitOrder")
		        .withProperty("Key", "3e6f5018cd")
		        .withProperty("POSID", posId)
		        .withProperty("CardID", CardID)
		        .withProperty("NoteID", buyin.getOrderId())
		        .withProperty("GoodName", buyin.getGoodId())
		        .withProperty("CategoryID", buyin.getCategoryId())
		        .withProperty("Orderdate", buyin.getBuyinDate())
		        .withProperty("Price", ""+buyin.getTotal())
		        .withProperty("Count", buyin.getCount())
		        .withProperty("Units", buyin.getUnits())
		        .withProperty("Specification", buyin.getSpecification())
		        .withProperty("Ispayed", ""+buyin.isPayed())
		        .withProperty("IsReceived", ""+buyin.isReceived())
		        .withProperty("SupplierID", buyin.getSupplierId())
		        .withProperty("OpratorID", buyin.getOpratorId())
		        .build();

		@SuppressWarnings("unchecked")
		SoapObject vc = null;
		try {
			vc = (SoapObject) soap.execute(getProjects);
			System.out.println("#####################vc="+vc);
		} catch (org.apache.http.auth.AuthenticationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (vc == null) return false;


		if ("true".equals(vc.toString())) {
			return true;
		}
		return false;
	}

}
